﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Web;

namespace MobiMap_Service.Models
{
    public class Helper
    {
        public static Image byteArrayToImage(byte[] byteArrayIn)
        {
            MemoryStream ms = new MemoryStream(byteArrayIn);
            Image returnImage = Image.FromStream(ms);
            return returnImage;
        }

        public static byte[] imageToByteArray(Image imageIn)
        {
            MemoryStream ms = new MemoryStream();
            imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
            return ms.ToArray();
        }

        public static double[] getArrayDouble(string st)
        {
            int n = 0;
            for(int i=0; i<st.Length; i++)
            {
                if (st[i] == '|')
                    n++;
            }
            double[] kq = new double[n];
            int j = 0;
            int startIndex = 0;
            for (int i = 0; i < st.Length; i++ )
            {
                if (st[i] == '|')
                {
                    string temp = st.Substring(startIndex, i - startIndex);
                    startIndex = i+1;
                    kq[j] = double.Parse(temp);
                    j++;
                }
            }
            return kq;
        }
        public static string ChuanHoaDuongDan(string folderName)
        {
            string path = AppDomain.CurrentDomain.BaseDirectory;
            path = path.Remove(path.LastIndexOf("\\"));
            path = path.Remove(path.LastIndexOf("\\") + 1);
            path = path + @"WebUI\MobiMap\" + folderName;
            return path;
        }
    }
}